package com.kele.cal.log;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

import java.util.Arrays;

/**
 * @Version 2019
 * @Author:kele
 * @Date:2021/6/6
 * @Content:
 * @Description：
 */
@Component
@Aspect
public class LoggerAspect {
    @Before("execution(public int com.kele.cal.impl.CalImpl.*(..))")
    public void before(JoinPoint joinPoint){
        String name = joinPoint.getSignature().getName();
        String args = Arrays.toString(joinPoint.getArgs());
        System.out.println(name+"⽅法的参数是"+args);

    }
    @After("execution(public int com.kele.cal.impl.CalImpl.*(..))")
    public void after(JoinPoint joinPoint){
        String name = joinPoint.getSignature().getName();
        System.out.println(name+"⽅法执⾏完毕");
    }
    @AfterReturning(value = "execution(public int com.kele.cal.impl.CalImpl.*(..))",returning = "result")
    public void afterReturn(JoinPoint joinPoint,Object result){
        String name = joinPoint.getSignature().getName();
        System.out.println(name+"⽅法的结果是"+result);
    }
    @AfterThrowing(value = "execution(public int com.kele.cal.impl.CalImpl.*(..))",throwing = "ex")
    public void afterThrowing(JoinPoint joinPoint,Exception ex){
        String name = joinPoint.getSignature().getName();
        System.out.println(name+"⽅法抛出异常"+ex);
    }

}
